package com.example.data.permission.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.data.permission.dao.BsdAccountMapper;
import com.example.data.permission.dao.UserMapper;
import com.example.data.permission.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author demo
 * @since 2021-07-22
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserMapper userMapper;
    @Autowired
    BsdAccountMapper bsdAccountMapper;

    /**
     * 测试 shop_id  in
     */
    @PostMapping("/test3")
    public Object test3() {
        return bsdAccountMapper.selectList(Wrappers.emptyWrapper());

    }

    /**
     * 测试 shop_id  in
     */
    @PostMapping("/test4")
    public Object test4(String name) {
        int i = 5 / 0;
        return bsdAccountMapper.selectList(Wrappers.emptyWrapper());

    }

    /**
     * 测试自定义数据权限
     * mrguo用户，数据库查询权限，只能查询某些字段和自己自己创建的数据
     */
    @GetMapping("/test2")
    public Object test2() {
        User user = new User();
        user.setUid(0L);
        user.setUsername("hahha");
        return bsdAccountMapper.selectAccountsByUser(user, "mrguo");
    }


    /**
     * 测试自定义数据权限
     * 自定义数据权限: mrguo用户 只能查看2021年之后的数据
     */
    @GetMapping("/test1")
    public Object test1() {
        return bsdAccountMapper.selectAccounts();
    }
}

